##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
# Copyright (c) 2003-2004 AT Content Types development team
# Copyright (c) 2005 Dan Keshet
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################

from UserDict import UserDict
from Products.Archetypes.public import registerType
from Products.ArchSurvey.config import PROJECTNAME

class _QuestionRegistry(UserDict):
    """Registry for Question """

    def __init__(self, *args, **kwargs):
        UserDict.__init__(self, *args, **kwargs)

    def register(self, Question, projectname=PROJECTNAME):
        id = Question.meta_type
        self[id] = Question
        registerType(Question, projectname)

    def unregister(self, Question):
        id = Question.meta_type
        self.pop(id)

    def listTypes(self):
        return self.keys()

    def listQuestions(self):
        return self.values()

    def listMetaAndShort(self):
        return [(x.meta_type,x.shortDesc) for x in self.values()]

QuestionRegistry = _QuestionRegistry()
registerQuestion = QuestionRegistry.register
unregisterQuestion = QuestionRegistry.unregister

# Question
from StandardQuestions import *